﻿Imports MyDLL

Public Class Form6

    Dim Nav As New MyDLL.RecordNav

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Try
            Dim total As Double
            Dim in1 As Double = TextBox8.Text
            Dim in2 As Double = TextBox9.Text
            Dim in3 As Double = TextBox11.Text
            Dim in4 As Double = TextBox13.Text
            Dim in5 As Double = TextBox15.Text
            Dim in6 As Double = TextBox17.Text
            Dim in7 As Double = TextBox19.Text
            Dim in8 As Double = TextBox21.Text
            Dim in9 As Double = TextBox23.Text
            Dim in10 As Double = TextBox25.Text

            total = in1 + in2 + in3 + in4 + in5 + in6 + in7 + in8 + in9 + in10
            TextBox31.Text = total

            TextBox29.Text = TextBox29.Text + total
            TextBox33.Text = TextBox29.Text * (118 / 100)
            TextBox30.Text = TextBox33.Text - TextBox29.Text

        Catch ex As Exception

            MsgBox("Please insert the needed values!")

        End Try

        Dim totalnoVAT As Double = TextBox31.Text
        Dim totalVAT As Double

        totalVAT = totalnoVAT * (118 / 100)
        TextBox28.Text = totalVAT

        Try

            totalVAT = TextBox28.Text
            Dim VAT As Double

            VAT = totalVAT - totalnoVAT
            TextBox27.Text = VAT

        Catch ex As Exception

            MsgBox("Please insert the needed values!")

        End Try


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim C As String = TextBox71.Text
        Dim Month As String = TextBox4.Text
        Dim Year As String = TextBox5.Text

        If CheckBox1.Checked Then
            Dim Datexml As XElement = _
            <Date>
                <Month><%= Month %></Month>
                <Year><%= Year %></Year>
            </Date>

            Form1.RichTextBox1.Text = Form1.RichTextBox1.Text & "<Report>" & vbCr _
                                      & "<Type>Petrol Reports</Type>" & vbCr & Datexml.ToString & vbCr
        End If

        If CheckBox2.Checked Then
            Dim Datexaml As XElement = _
            <Paragraph FontFamily="Arial" FontSize="20pt">
                Petrol Report for <%= Month %>,<%= Year %>
            </Paragraph>

            Form1.RichTextBox2.Text = Form1.RichTextBox2.Text & _
            "<FlowDocument xmlns=" & C & "http://schemas.microsoft.com/winfx/2006/xaml/presentation" & C & ">" & vbCr _
            & Datexaml.ToString & vbCr
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim Count As String = TextBox61.Text
        Dim GTotalVAT As String = TextBox33.Text
        Dim GVAT As String = TextBox30.Text
        Dim GTotalnoVAT As String = TextBox29.Text

        If CheckBox1.Checked Then
            Dim Counter As XElement = _
            <Counter>
                <Count><%= Count %></Count>
            </Counter>

            Dim GTxml As XElement = _
            <Totals>
                <GTotalnoVAT><%= GTotalnoVAT %></GTotalnoVAT>
                <GVAT><%= GVAT %></GVAT>
                <GTotalVat><%= GTotalVAT %></GTotalVat>
            </Totals>

            Form1.RichTextBox1.Text = Form1.RichTextBox1.Text & GTxml.ToString & vbCr & Counter.ToString & vbCr & "</Report>"
        End If

        If CheckBox2.Checked Then
            Dim GTxaml As XElement = _
            <List FontFamily="Arial" FontSize="11pt">
                <ListItem><Paragraph>Grand Total (Without VAT) :<%= GTotalnoVAT %></Paragraph></ListItem>
                <ListItem><Paragraph>VAT in Grand Total:<%= GVAT %></Paragraph></ListItem>
                <ListItem><Paragraph>Grand Total (With VAT) :<%= GTotalVAT %></Paragraph></ListItem>
            </List>

            Form1.RichTextBox2.Text = Form1.RichTextBox2.Text & GTxaml.ToString & vbCr & "</FlowDocument>"
        End If

    End Sub

    Private Sub WriteData()
        Dim ID As Integer = TextBox61.Text
        Dim No As String = TextBox6.Text

        Dim totalnoVAT As String = TextBox31.Text
        Dim in1 As String = TextBox8.Text
        Dim in2 As String = TextBox9.Text
        Dim in3 As String = TextBox11.Text
        Dim in4 As String = TextBox13.Text
        Dim in5 As String = TextBox15.Text
        Dim in6 As String = TextBox17.Text
        Dim in7 As String = TextBox19.Text
        Dim in8 As String = TextBox21.Text
        Dim in9 As String = TextBox23.Text
        Dim in10 As String = TextBox25.Text
        Dim VAT As String = TextBox27.Text
        Dim totalVAT As String = TextBox28.Text

        Dim in1n As String = TextBox7.Text
        Dim in2n As String = TextBox10.Text
        Dim in3n As String = TextBox12.Text
        Dim in4n As String = TextBox14.Text
        Dim in5n As String = TextBox16.Text
        Dim in6n As String = TextBox18.Text
        Dim in7n As String = TextBox20.Text
        Dim in8n As String = TextBox22.Text
        Dim in9n As String = TextBox24.Text
        Dim in10n As String = TextBox26.Text

        If CheckBox3.Checked Then
            ID = ID + 1
            TextBox61.Text = ID
        End If

        If CheckBox1.Checked Then
            Dim Carxml As XElement = _
            <Car>
                <Info>
                    <No id=<%= ID %>><%= No %></No>
                    <totalnoVAT id=<%= ID %>><%= totalnoVAT %></totalnoVAT>
                    <VAT id=<%= ID %>><%= VAT %></VAT>
                    <totalVAT id=<%= ID %>><%= totalVAT %></totalVAT>
                </Info>
                <Invoices>
                    <in1>
                        <in1n id=<%= ID %>><%= in1n %></in1n>
                        <in1 id=<%= ID %>><%= in1 %></in1>
                    </in1>
                    <in2>
                        <in2n id=<%= ID %>><%= in2n %></in2n>
                        <in2 id=<%= ID %>><%= in2 %></in2>
                    </in2>
                    <in3>
                        <in3n id=<%= ID %>><%= in3n %></in3n>
                        <in3 id=<%= ID %>><%= in3 %></in3>
                    </in3>
                    <in4>
                        <in4n id=<%= ID %>><%= in4n %></in4n>
                        <in4 id=<%= ID %>><%= in4 %></in4>
                    </in4>
                    <in5>
                        <in5n id=<%= ID %>><%= in5n %></in5n>
                        <in5 id=<%= ID %>><%= in5 %></in5>
                    </in5>
                    <in6>
                        <in6n id=<%= ID %>><%= in6n %></in6n>
                        <in6 id=<%= ID %>><%= in6 %></in6>
                    </in6>
                    <in7>
                        <in7n id=<%= ID %>><%= in7n %></in7n>
                        <in7 id=<%= ID %>><%= in7 %></in7>
                    </in7>
                    <in8>
                        <in8n id=<%= ID %>><%= in8n %></in8n>
                        <in8 id=<%= ID %>><%= in8 %></in8>
                    </in8>
                    <in9>
                        <in9n id=<%= ID %>><%= in9n %></in9n>
                        <in9 id=<%= ID %>><%= in9 %></in9>
                    </in9>
                    <in10>
                        <in10n id=<%= ID %>><%= in10n %></in10n>
                        <in10 id=<%= ID %>><%= in10 %></in10>
                    </in10>
                </Invoices>
            </Car>

            Form1.RichTextBox1.Text = Form1.RichTextBox1.Text & Carxml.ToString & vbCr

        End If

        If CheckBox2.Checked Then

            Dim Carxaml As XElement = _
            <List FontFamily="Arial" FontSize="11pt">
                <ListItem><Paragraph>ID:<%= ID %></Paragraph></ListItem>
                <ListItem><Paragraph>Car No.:<%= No %></Paragraph></ListItem>
                <ListItem><Paragraph>Total (Without VAT):<%= totalnoVAT %></Paragraph></ListItem>
                <ListItem><Paragraph>VAT in Total:<%= VAT %></Paragraph></ListItem>
                <ListItem><Paragraph>Total(With VAT) :<%= totalVAT %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in1n %> , Amount:<%= in1 %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in2n %> , Amount:<%= in2 %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in3n %> , Amount:<%= in3 %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in4n %> , Amount:<%= in4 %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in5n %> , Amount:<%= in5 %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in6n %> , Amount:<%= in6 %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in7n %> , Amount:<%= in7 %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in8n %> , Amount:<%= in8 %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in9n %> , Amount:<%= in9 %></Paragraph></ListItem>
                <ListItem><Paragraph>Invoice No:<%= in10n %> , Amount:<%= in10 %></Paragraph></ListItem>
            </List>

            Form1.RichTextBox2.Text = Form1.RichTextBox2.Text & Carxaml.ToString & vbCr
        End If

        If CheckBox1.Checked Or CheckBox2.Checked Then
            TextBox6.Text = ""
            TextBox28.Text = "0"
            TextBox31.Text = "0"
            TextBox8.Text = "0"
            TextBox9.Text = "0"
            TextBox11.Text = "0"
            TextBox13.Text = "0"
            TextBox15.Text = "0"
            TextBox17.Text = "0"
            TextBox19.Text = "0"
            TextBox21.Text = "0"
            TextBox23.Text = "0"
            TextBox25.Text = "0"
            TextBox27.Text = "0"
            TextBox7.Text = ""
            TextBox10.Text = ""
            TextBox12.Text = ""
            TextBox14.Text = ""
            TextBox16.Text = ""
            TextBox18.Text = ""
            TextBox20.Text = ""
            TextBox22.Text = ""
            TextBox24.Text = ""
            TextBox26.Text = ""
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        WriteData()
    End Sub
    Private Sub LoadData()

        Try
            Me.Text = "Petrol Reports Database" & " - " & Form1.TextBox3.Text

            Dim ID As String = TextBox61.Text

            Dim Report As XElement = XElement.Load(Form1.TextBox7.Text & Form1.TextBox3.Text & ".xml")

            Dim No As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Info>.<No> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox6.Text = No

            Dim totalnoVAT As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Info>.<totalnoVAT> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox31.Text = totalnoVAT

            Dim VAT As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Info>.<VAT> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox27.Text = VAT

            Dim totalVAT As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Info>.<totalVAT> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox28.Text = totalVAT

            Dim in1n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in1>.<in1n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox7.Text = in1n

            Dim in1 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in1>.<in1> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox8.Text = in1

            Dim in2n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in2>.<in2n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox10.Text = in2n

            Dim in2 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in2>.<in2> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox9.Text = in2

            Dim in3n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in3>.<in3n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox12.Text = in3n

            Dim in3 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in3>.<in3> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox11.Text = in3

            Dim in4n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in4>.<in4n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox14.Text = in4n

            Dim in4 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in4>.<in4> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox13.Text = in4

            Dim in5n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in5>.<in5n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox16.Text = in5n

            Dim in5 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in5>.<in5> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox15.Text = in5

            Dim in6n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in6>.<in6n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox18.Text = in6n

            Dim in6 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in6>.<in6> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox17.Text = in6

            Dim in7n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in7>.<in7n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox20.Text = in7n

            Dim in7 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in7>.<in7> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox19.Text = in7

            Dim in8n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in8>.<in8n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox22.Text = in8n

            Dim in8 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in8>.<in8> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox21.Text = in8

            Dim in9n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in9>.<in9n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox24.Text = in9n

            Dim in9 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in9>.<in9> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox23.Text = in9

            Dim in10n As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in10>.<in10n> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox26.Text = in10n

            Dim in10 As XElement = _
                <Root>
                    <%= From el In Report.<Car>.<Invoices>.<in10>.<in10> _
                        Where el.Attribute("id") = ID _
                        Select el %>
                </Root>
            TextBox25.Text = in10

            Dim Month As XElement = _
                <Root>
                    <%= From el In Report.<Date>.<Month> _
                        Select el %>
                </Root>
            TextBox4.Text = Month

            Dim Year As XElement = _
                <Root>
                    <%= From el In Report.<Date>.<Year> _
                        Select el %>
                </Root>
            TextBox5.Text = Year

            Dim GTotalnoVAT As XElement = _
                <Root>
                    <%= From el In Report.<Totals>.<GTotalnoVAT> _
                        Select el %>
                </Root>
            TextBox29.Text = GTotalnoVAT

            Dim GVAT As XElement = _
                <Root>
                    <%= From el In Report.<Totals>.<GVAT> _
                        Select el %>
                </Root>
            TextBox30.Text = GVAT

            Dim GTotalVAT As XElement = _
                <Root>
                    <%= From el In Report.<Totals>.<GTotalVat> _
                        Select el %>
                </Root>
            TextBox33.Text = GTotalVAT


            Dim Count As XElement = _
       <Root>
           <%= From el In Report.<Counter>.<Count> _
               Select el %>
       </Root>

            Dim Counter As String = Count

            Label7.Text = "There are " & Counter & " record(s) in the XML file"
        Catch ex As Exception
            MsgBox("No file has been loaded.")

        End Try
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        LoadData()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Try
            Do Until TextBox61.Text = TextBox81.Text
                CheckBox3.CheckState = CheckState.Unchecked
                Dim ID As Integer = TextBox61.Text
                ID = ID + 1
                TextBox61.Text = ID
                LoadData()
                WriteData()
            Loop
        Catch ex As Exception
            MsgBox("Choose a proper range.")
        End Try
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Nav.GoToFirst(TextBox61)

        LoadData()
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        Nav.PrevRec(TextBox61)

        LoadData()
    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        Nav.NextRec(TextBox61)

        LoadData()
    End Sub

    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        Nav.GoToLast(TextBox61, Form1.TextBox7.Text & Form1.TextBox3.Text & ".xml")

        LoadData()
    End Sub
End Class